package io.kiki.sba.registry.common.model.metaserver.inter.heartbeat;

import io.kiki.sba.registry.common.model.Node;
import io.kiki.sba.registry.common.model.slot.BaseSlotStatus;
import io.kiki.sba.registry.common.model.slot.SlotBasicInfo;
import io.kiki.sba.registry.common.model.slot.Slots;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;
import java.util.Map;


public class HeartbeatRequest<T extends Node> implements Serializable {

    @Getter
    private final T node;
    @Getter
    private final long slotsEpoch;
    @Getter
    private final String dataCenter;
    @Getter
    private final long timestamp;
    @Getter
    private final SlotBasicInfo slotBasicInfo;
    private final List<BaseSlotStatus> slotStatuses;
    // <cluster, slotsEpoch>
    @Getter
    private final Map<String, Long> remoteClusterslotsEpoch;
    @Setter
    @Getter
    private int duration;
    @Getter
    private Slots slots;


    public HeartbeatRequest(T node, long slotsEpoch, String dataCenter, long timestamp, SlotBasicInfo slotBasicInfo, Map<String, Long> remoteClusterslotsEpoch) {
        this.node = node;
        this.slotsEpoch = slotsEpoch;
        this.dataCenter = dataCenter;
        this.timestamp = timestamp;
        this.slotBasicInfo = slotBasicInfo;
        this.slotStatuses = Collections.emptyList();
        this.remoteClusterslotsEpoch = remoteClusterslotsEpoch;
    }


    public HeartbeatRequest(T node, long slotsEpoch, String dataCenter, long timestamp, SlotBasicInfo slotBasicInfo, final List<BaseSlotStatus> slotStatuses, Map<String, Long> remoteClusterslotsEpoch) {
        this.node = node;
        this.slotsEpoch = slotsEpoch;
        this.dataCenter = dataCenter;
        this.timestamp = timestamp;
        this.slotBasicInfo = slotBasicInfo;
        this.slotStatuses = slotStatuses;
        this.remoteClusterslotsEpoch = remoteClusterslotsEpoch;
    }


    public List<BaseSlotStatus> getSlotStatuses() {
        return slotStatuses;
    }


    public HeartbeatRequest<T> setSlots(Slots slots) {
        this.slots = slots;
        return this;
    }


}
